package com.kaishengit.pojo;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

@Entity
@Table(name="t_user")
public class User {
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private int id;
	private String username;
	private String userpwd;
	private String createtime;
	private boolean isenable;
	private int role;
	
	@OneToMany(mappedBy="user",fetch=FetchType.LAZY,cascade=CascadeType.PERSIST)
	private List<Message> messages;
	
	@OneToMany(mappedBy="user",cascade=CascadeType.PERSIST)
	private List<Talk> talks;
	
	@ManyToMany(mappedBy="users",cascade=CascadeType.PERSIST)
	private List<Project> projects;
	
	@OneToMany(mappedBy="createuser",cascade=CascadeType.PERSIST)
	private List<Issues> createIssues;
	
	@OneToMany(mappedBy="workuser",cascade=CascadeType.PERSIST,fetch=FetchType.LAZY)
	private List<Issues> workIssues;
	
	@ManyToMany(mappedBy="userList",cascade=CascadeType.PERSIST)
	private List<Group> groupList;
	
	
	@Transient
	public Set<String> getGroupNameSet(){
		Set<String> set = new HashSet<String>();
		for(Group g : groupList){
			set.add(g.getName());
		}
		return set;
	}
	
	
	//get and set
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public String getUserpwd() {
		return userpwd;
	}
	public void setUserpwd(String userpwd) {
		this.userpwd = userpwd;
	}
	public String getCreatetime() {
		return createtime;
	}
	public void setCreatetime(String createtime) {
		this.createtime = createtime;
	}
	public boolean isIsenable() {
		return isenable;
	}
	public void setIsenable(boolean inenable) {
		this.isenable = inenable;
	}
	public int getRole() {
		return role;
	}
	public void setRole(int role) {
		this.role = role;
	}
	public List<Message> getMessages() {
		return messages;
	}
	public void setMessages(List<Message> messages) {
		this.messages = messages;
	}
	public List<Talk> getTalks() {
		return talks;
	}
	public void setTalks(List<Talk> talks) {
		this.talks = talks;
	}
	public List<Project> getProjects() {
		return projects;
	}
	public void setProjects(List<Project> projects) {
		this.projects = projects;
	}
	public List<Issues> getCreateIssues() {
		return createIssues;
	}
	public void setCreateIssues(List<Issues> createIssues) {
		this.createIssues = createIssues;
	}
	public List<Issues> getWorkIssues() {
		return workIssues;
	}
	public void setWorkIssues(List<Issues> workIssues) {
		this.workIssues = workIssues;
	}
	public void setGroupList(List<Group> groupList) {
		this.groupList = groupList;
	}
	public List<Group> getGroupList() {
		return groupList;
	}
	
}
